﻿Imports System.Data
Partial Class Egresados_RegEgresado
    Inherits PaginaComun

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles BtnGuardar.Click
        Dim obj As New Personas
        obj.CEDULA = TxtId.Value
        obj.TIP_DOC = CmbTipId.SelectedValue
        obj.LUG_EXP_DOC = TxtLugExp.Text
        obj.FEC_EXP_DOC = DtpFecExp.SelectedDate
        obj.PRIMER_APELLIDO = TxtApe1.Text
        obj.SEGUNDO_APELLIDO = TxtApe2.Text
        obj.PRIMER_NOMBRE = TxtNom1.Text
        obj.SEGUNDO_NOMBRE = TxtNom2.Text
        obj.LM = TxtLib.Text
        obj.DM = TxtDist.Text
        obj.TP = TxtTP.Text
        obj.ESTADO_CIVIL = CmbEstCivil.SelectedValue
        obj.GRUPO_SANGUINEO = CmbSangre.SelectedValue
        obj.RELIGION = CmbReligion.SelectedValue
        obj.SEXO = CmbSexo.SelectedValue
        obj.DPTO_NTO = CmbDptoNac.SelectedValue
        obj.MCPIO_NTO = CmbMunNac.SelectedValue
        obj.FECHA_NACIMIENTO = DtpFecNac.SelectedDate
        obj.DIRECCION = TxtDir.Text
        obj.TELEFONO = TxtTel.Text
        obj.CELULAR = TxtCel.Text
        obj.FAX = TxtFax.Text
        obj.EMAIL = TxtEmail.Text
        obj.DPTO_RESIDENCIA = CmbDptoUbi.SelectedValue
        obj.MUN_RESIDENCIA = CmbMunUbi.SelectedValue
        obj.IDPK = Me.Pk1
        Select Case Me.Oper
            Case "Editar"
                MsgModalPanel.Text = obj.Update
                If obj.lErrorG = False Then
                    ImgRst.ImageUrl = "~/imagenes/good.png"
                Else
                    ImgRst.ImageUrl = "~/imagenes/error.png"
                End If
                ModalPopup.Show()
                Me.Oper = ""
                habilitar(False)
        End Select
    End Sub

    Sub limpiar()

    End Sub

    Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) 'Handles ImageButton2.Click

    End Sub

    Protected Sub ImageButton4_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton4.Click
        Dim obj As New Personas
        Dim dt As DataTable = obj.GetbyPK(Me.TxtCedulaB.Text)
        habilitar(False)
        If dt.Rows.Count > 0 Then
            Me.TxtId.Text = dt.Rows(0)("Cedula").ToString
            Me.CmbTipId.SelectedValue = dt.Rows(0)("Tip_Doc").ToString
            Me.TxtLugExp.Text = dt.Rows(0)("Lug_exp_doc").ToString
            Me.DtpFecExp.SelectedDate = dt.Rows(0)("fec_exp_doc").ToString
            Me.TxtNom1.Text = dt.Rows(0)("Primer_nombre").ToString
            Me.TxtNom2.Text = dt.Rows(0)("Segundo_Nombre").ToString
            Me.TxtApe1.Text = dt.Rows(0)("Primer_Apellido").ToString
            Me.TxtApe2.Text = dt.Rows(0)("Segundo_Apellido").ToString
            Me.TxtLib.Text = dt.Rows(0)("LM").ToString
            Me.TxtDist.Text = dt.Rows(0)("DM").ToString
            Me.CmbEstCivil.SelectedValue = dt.Rows(0)("Estado_Civil").ToString
            Me.CmbSangre.SelectedValue = dt.Rows(0)("Grupo_Sanguineo").ToString
            Me.CmbReligion.SelectedValue = dt.Rows(0)("Religion").ToString
            Me.CmbSexo.SelectedValue = dt.Rows(0)("Sexo").ToString
            Me.TxtTP.Text = dt.Rows(0)("TP").ToString
            Me.CmbDptoNac.SelectedValue = dt.Rows(0)("Dpto_Nto").ToString
            Me.CmbMunNac.SelectedValue = dt.Rows(0)("Mcpio_Nto").ToString
            Me.DtpFecNac.SelectedDate = dt.Rows(0)("Fecha_Nacimiento").ToString
            TxtDir.Text = dt.Rows(0)("Direccion").ToString
            Me.TxtTel.Text = dt.Rows(0)("Telefono").ToString
            Me.TxtCel.Text = dt.Rows(0)("Celular").ToString
            Me.TxtFax.Text = dt.Rows(0)("Fax").ToString
            Me.TxtEmail.Text = dt.Rows(0)("Email").ToString
            Me.CmbDptoUbi.SelectedValue = dt.Rows(0)("Dpto_Residencia").ToString
            Me.CmbMunUbi.SelectedValue = dt.Rows(0)("Mun_Residencia").ToString
            Me.Pk1 = dt.Rows(0)("Cedula").ToString
            Me.MultiView1.ActiveViewIndex = 0
        End If
    End Sub

    Protected Sub ImageButton5_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton5.Click
        If TxtId.Text = "" Then
            MsgModalPanel.Text = "Debe buscar un egresado para actualizar datos."
            ModalPopup.Show()
        Else
            habilitar(True)
            Me.Oper = "Editar"
        End If
    End Sub
    Sub habilitar(ByVal v As Boolean)
        Me.TxtId.Enabled = v
        Me.CmbTipId.Enabled = v
        Me.TxtLugExp.Enabled = v
        Me.DtpFecExp.Enabled = v
        Me.TxtNom1.Enabled = v
        Me.TxtNom2.Enabled = v
        Me.TxtApe1.Enabled = v
        Me.TxtApe2.Enabled = v
        Me.TxtLib.Enabled = v
        Me.TxtDist.Enabled = v
        Me.CmbEstCivil.Enabled = v
        Me.CmbSangre.Enabled = v
        Me.CmbReligion.Enabled = v
        Me.CmbSexo.Enabled = v
        Me.TxtTP.Enabled = v
        Me.CmbDptoNac.Enabled = v
        Me.CmbMunNac.Enabled = v
        Me.DtpFecNac.Enabled = v
        TxtDir.Enabled = v
        Me.TxtTel.Enabled = v
        Me.TxtCel.Enabled = v
        Me.TxtFax.Enabled = v
        Me.TxtEmail.Enabled = v
        Me.CmbDptoUbi.Enabled = v
        Me.CmbMunUbi.Enabled = v
        Me.BtnGuardar.Enabled = v
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            CompareValidator2.ValueToCompare = Today
            CompareValidator3.ValueToCompare = Today
            CompareValidator4.ValueToCompare = Today
            CompareValidator5.ValueToCompare = Today
            CompareValidator1.Enabled = False
            RequiredFieldValidator1.Enabled = False
            DtpFechaGrado.SelectedDate = Today
            DtpFechaIng.SelectedDate = Today
            habilitar(False)
            Me.Oper = ""
        End If
    End Sub

    Protected Sub BtnVolver_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles BtnVolver.Click
        If Me.Oper = "Editar" Then
            MsgModalPanel.Text = "Debe finalizar la edicion para registrar el egresado"
            ModalPopup.Show()
            Exit Sub
        End If
        Dim obj As New Egresados
        MsgModalPanel.Text = obj.Egresar(Me.TxtId.Text, CmbFacultad.SelectedValue, CmbPrograma.SelectedValue, CmbTipEstudio.SelectedValue, TxtTitulo.Text, DtpFechaIng.SelectedDate, DtpFechaGrado.SelectedDate, CmbEstado.SelectedValue)
        If obj.lErrorG = False Then
            ImgRst.ImageUrl = "~/imagenes/good.png"
            Membership.CreateUser(Me.TxtId.Text, Me.TxtId.Text & ".")
            Dim objPer As New DBMenu
            Me.MsgModalPanel.Text += "<BR/>" + objPer.AsigPerfilUser("Estudiantes", Me.TxtId.Text)
        Else
            ImgRst.ImageUrl = "~/imagenes/error.png"
        End If
        ModalPopup.Show()
        habilitar(False)
    End Sub

    Protected Sub ImageButton6_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton6.Click
        habilitar(False)
        Me.Oper = ""
    End Sub

    Protected Sub CmbEstado_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmbEstado.DataBound
        If CmbEstado.SelectedValue = "EG" Then
            Me.CompareValidator1.Enabled = True
            Me.RequiredFieldValidator1.Enabled = True
        Else
            Me.CompareValidator1.Enabled = False
            Me.RequiredFieldValidator1.Enabled = False
        End If
    End Sub

    Protected Sub CmbEstado_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmbEstado.SelectedIndexChanged
        If CmbEstado.SelectedValue = "EG" Then
            Me.CompareValidator1.Enabled = True
            Me.RequiredFieldValidator1.Enabled = True
        Else
            Me.CompareValidator1.Enabled = False
            Me.RequiredFieldValidator1.Enabled = False
        End If
    End Sub
End Class
